package com.ruoyi.energy.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.energy.domain.NyTransLoad;
import com.ruoyi.energy.service.INyTransLoadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * energyController
 *
 * @author cjie
 * @date 2021-10-12
 */
@Api(tags = " 箱变负荷记录")
@RestController
@RequestMapping("/nyTransLoad")
public class NyTransLoadController extends BaseController {
    @Autowired
    private INyTransLoadService nyTransLoadService;

    /**
     * 查询energy列表
     */
    @ApiOperation(value="查询箱变负荷列表", notes="查询箱变负荷列表")
    @PreAuthorize(hasPermi = "energy:nyTransLoad:list")
    @GetMapping("/list")
    public TableDataInfo list(NyTransLoad nyTransLoad) {
        startPage();
        List<NyTransLoad> list = nyTransLoadService.selectNyTransLoadList(nyTransLoad);
        return getDataTable(list);
    }

    /**
     * 导出energy列表
     */
    @ApiOperation(value="导出箱变负荷记录", notes="导出箱变负荷记录")
    @PreAuthorize(hasPermi = "energy:nyTransLoad:export")
    @Log(title = "energy", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NyTransLoad nyTransLoad) throws IOException {
        List<NyTransLoad> list = nyTransLoadService.selectNyTransLoadList(nyTransLoad);
        ExcelUtil<NyTransLoad> util = new ExcelUtil<NyTransLoad>(NyTransLoad.class);
        util.exportExcel(response, list, "energy数据");
    }
    /**
     * 获取energy详细信息
     */
    @ApiOperation(value="获取箱变负荷详细信息", notes="获取箱变负荷详细信息")
    @PreAuthorize(hasPermi = "energy:nyTransLoad:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(nyTransLoadService.selectNyTransLoadById(id));
    }

    /**
     * 新增energy
     */
    @ApiOperation(value="新增箱变负荷记录", notes="新增箱变负荷")
    @PreAuthorize(hasPermi = "energy:nyTransLoad:add")
    @Log(title = "energy", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NyTransLoad nyTransLoad) {
        return toAjax(nyTransLoadService.insertNyTransLoad(nyTransLoad));
    }

    /**
     * 修改energy
     */
    @ApiOperation(value="修改箱变负荷记录", notes="修改箱变负荷记录")
    @PreAuthorize(hasPermi = "energy:nyTransLoad:edit")
    @Log(title = "energy", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NyTransLoad nyTransLoad) {
        return toAjax(nyTransLoadService.updateNyTransLoad(nyTransLoad));
    }

    /**
     * 删除energy
     */
    @ApiOperation(value="删除箱变负荷记录", notes="删除箱变负荷记录")
    @ApiImplicitParam(name = "ids", value = "energyID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "energy:nyTransLoad:remove")
    @Log(title = "energy", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(nyTransLoadService.deleteNyTransLoadByIds(ids));
    }



}
